'use strict';
/**
 * @ngdoc service
 * @name elmApp.elmMsg
 * @description
 * # elmMsg
 * Factory in the elmApp.
 */
angular.module('fscApp')
    .directive('recorderRightDoc', function(global,dialog,msg,$q,msgRegister,sync){
        return {
            restrict: 'E',
            templateUrl: '/node_static/javascripts/app/view/directive/recorder_right_doc.html',
            replace: true,
            scope: {
                recorder: '='
            },
            link: function (scope, element, attrs){
                scope.resUrl = global.cache.resUrl;
                scope.fillZero = function (num, digit) {
                    digit = digit || 2;
                    num = num + "";
                    var len = num.length;
                    var diff = digit - len;
                    if (diff <= 0) {
                        return num;
                    } else {
                        return (new Array(diff + 1)).join("0") + num;
                    }
                }
                var imgStr = "png,jpg,jpeg,bmp,gif"
                scope.document=function(message) {
                    if(message.pngPath){
                        scope.open(message)
                    }else  if(imgStr.indexOf(message.fileType)>=0){
                        scope.open(message,true)
                    }else{
                        msg.info("文档转换中或者不是office文件");
                    }
                };
                scope.open = function(message,img){
                    dialog.complexBox(
                        {
                            templateUrl: '/node_static/javascripts/app/view/menus/doc-menu.html',
                            windowClass:'modal-content-opacity',
                            size:'md',
                            onComplete: function (dialogScope,modalInstance) {
                                dialogScope.message = message
                                dialogScope.resUrl = scope.resUrl
                                dialogScope.magnify = function(){
                                    var width = $(".dialog-img img").width()
                                    if(width<800){
                                        $(".dialog-img img").css("width",width*2+"px")
                                        $(".modal-dialog").css("width",width*2.2+42+"px")
                                    }
                                }
                                dialogScope.slide = function (index) {
                                    if (index > 0&&index<=message.pngCount) {
                                        dialogScope.fileUrl =dialogScope.resUrl+"/"+ message.pngPath+ '-' + (scope.fillZero(index, message.pngCount.length)) + '.jpg'
                                        dialogScope.filIndex = index
                                        $(".dialog-img img").css("width","100%")
                                        $(".modal-dialog").css("width","600px")
                                    }
                                }
                                if(img){
                                    dialogScope.fileUrl =dialogScope.resUrl+"/"+ message.filePath
                                    dialogScope.filIndex = 1
                                }else{
                                    dialogScope.slide(1)
                                }
                                dialogScope.closePhoto = function(){
                                    modalInstance.close();
                                };
                            }
                        })
                }
            }
        }
    })
